<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数据库管理</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script src="js/page.js"></script>
</head>

<body onload="initialize();">
<jsp:useBean id="database" class="DatabaseConnection.DatabaseConnection" />
<%@include file="connect_database.jsp" %>
<%
request.setCharacterEncoding("utf-8");
String database_name = request.getParameter("database");
String sql_check_database = "show databases like '" + database_name + "';";
ResultSet resultset_check_database = database.executeQuery(sql_check_database);
if (resultset_check_database != null && resultset_check_database.next() == true)
{
	String deleted_data = request.getParameter("deleted_data");
	String message = "";
	String [] deleted_tables = deleted_data.split(",");
	String successful_tables = "";
	String failed_tables = "";
	String sql_delete = "";
	boolean success = false;
	for (int i = 0; i < deleted_tables.length; i++)
	{
		sql_delete = "drop table " + deleted_tables[i] + ";";
		success = database.executeUpdate(sql_delete, database_name);
		if (success == true)
			successful_tables = successful_tables + deleted_tables[i] + ", ";
		else
			failed_tables = failed_tables + deleted_tables[i] + ", ";
	}
	if (successful_tables.length() > 0)
	{
		successful_tables = successful_tables.substring(0, successful_tables.length() - 2);
		message = message + "数据表 " + successful_tables + " 删除成功";
	}
	if (failed_tables.length() > 0)
	{
		failed_tables = failed_tables.substring(0, failed_tables.length() - 2);
		if (message.length() > 0)
			message = message + "，";
		message = message + "数据表 " + failed_tables + " 删除失败";
	}
	message = message + "！";
%>
<script type="text/javascript">
<!--
	window.alert("<%= message %>");
	window.location.href = "tables.jsp?database=<%= database_name %>";
//-->
</script>
<%
}
else
{
%>
<script type="text/javascript">
<!--
	window.alert("连接数据库 <%= database_name %> 失败！");
	window.location.href = "databases.jsp";
//-->
</script>
<%
}
if (resultset_check_database != null)
	resultset_check_database.close();
database.closeConnection();
%>
</body>
</html>